package com.wz.common.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * <p>Project: wz_api - SwaggerConfig
 * <p>Powered by pisces On 2022-01-16 17:10:45
 * <P>Created by IntelliJ IDEA
 *
 * @author ww606851@163.com
 * @version 1.0
 * @description:
 * @since 8
 */

@Configuration
@EnableOpenApi
public class SwaggerConfig {

    @Bean
    public Docket createDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                .enable(true)//为true可以访问 false不能访问
                .select()// 通过.select()方法，去配置扫描接口,RequestHandlerSelectors配置如何扫描接口
                .apis(RequestHandlerSelectors.basePackage("com.wz.controller"))
                // 配置如何通过path过滤,即这里只扫描请求以/api开头的接口
                .paths(PathSelectors.ant("/**")) //所有接口都能生成接口文档
                .build();
    }

    private ApiInfo getApiInfo() {
        return new ApiInfoBuilder()
                .title("后台管理系统框架")
                .description("后台管理系统框架搭建的接口文档，里面包含了所有的请求及参数信息")
                .contact(new Contact("wang", "http://localhost", "ww606851@163.com"))
                .version("v1.0")
                .build();
    }

}
